package com.letoken.platform.repo.mall.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.app.req.mall.NearbyShopsReq;
import com.letoken.platform.repo.app.req.mall.QueryMallOrderHistoryReq;
import com.letoken.platform.repo.app.req.mall.ShopsReq;
import com.letoken.platform.repo.app.req.mall.StoreReq;
import com.letoken.platform.repo.app.res.mall.*;
import com.letoken.platform.repo.ecommerce.vo.UserShopInfoRes;
import com.letoken.platform.repo.mall.po.AppMallInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 商铺基本信息表 Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2023-04-20
 */
public interface AppMallInfoMapper extends BaseMapper<AppMallInfo> {

    @Select("select 1 from app_mall_info where id = #{mallId} and user_id = #{userId} limit 1")
    Integer checkoutMallAndUserId(@Param("mallId") Integer mallId,@Param("userId") Integer userId);


    @Select("select * from app_mall_info where user_id = #{userId} ")
    AppMallInfo selectMallByUserId(@Param("userId") Integer userId);

    AppMallInfo getMallInfoByAddress(@Param("mallNumber")String mallNumber);


    Page<MallUserShopsRes> shops(@Param("page") Page<MallUserShopsRes> page , @Param("req") ShopsReq req);



    List<NearbyShopsRes> nearbyShops(@Param("req") NearbyShopsReq req);

    List<AppMallInfo> getAppMallInfoList();


    void updateBatchFollowersById(@Param("list") List<AppMallInfo> list);

    MallMatchmakingRes queryNameAndLogo(@Param("mallUserId") Integer mallUserId);

    List<MallMatchmakingRes> queryNameAndLogoList(@Param("mallUserIdList") List<Integer> mallUserIdList);



    @Select("select shipping_type from app_mall_info where id = #{mallId} limit 1")
    Integer selectShippingType(@Param("mallId") Integer mallId);



//    @Select("select s.user_id as mallUserId, s.id,s.ecommerce_name as mallName,s.ecommerce_logo as logo,(select count(1) from ecommerce_product p where p.mall_id = s.id and  p.publish_status = 0 and p.delete_status = 0 ) as count " +
//            " ,       (select ecommerce_contributing from app_mall_account where mall_id = s.id limit 1) as contributing " +
//            "   from app_mall_info s  where s.id = #{id}  ")
//    UserShopInfoRes obtainSimpleShop(@Param("id") Integer id);

    @Select("select s.user_id as mallUserId, s.id,s.ecommerce_name as mallName,s.ecommerce_logo as logo,(select count(1) " +
            " from ecommerce_product p where p.mall_id = s.id and  p.publish_status = 0 and p.delete_status = 0 ) as count " +
            "   from app_mall_info s  where s.id = #{id} and s.publish_state=0")
    UserShopInfoRes obtainSimpleShop(@Param("id") Integer id);

    Page<MallStoreRes> stores(@Param("page") Page<MallStoreRes> page , @Param("req") StoreReq req);



    Page<MallStoreCancelRes> storeCancelList(@Param("page") Page<MallStoreRes> page , @Param("req") StoreReq req);



    @Select("select s.user_id as mallUserId, s.id,s.ecommerce_name as mallName,s.ecommerce_logo as logo  from app_mall_info s  where s.id = #{id}  ")
    UserShopInfoRes simpleShop(@Param("id") Integer id);


    @Select("select count(1) from app_mall_info where state = 1")
    Integer count();

    @Select("select count(1) from app_mall_info where state = 1  and date(update_time) = date(CURRENT_TIMESTAMP)")
    Integer countToday();


}
